package mongodb

import (
	"context"
	"go.uber.org/zap"
	"golang-sgg-daijia/internal/model"
)

type OrderMonitorRecordDao interface {
	InsertOne(ctx context.Context, orderMonitorRecord *model.OrderMonitorRecord) (bool, error)
}

type orderMonitorRecordDao struct {
	*MongoClient
}

func NewOrderMonitorRecordDao(
	r *MongoClient,
) OrderMonitorRecordDao {
	return &orderMonitorRecordDao{
		r,
	}
}

func (r *orderMonitorRecordDao) InsertOne(ctx context.Context, orderMonitorRecord *model.OrderMonitorRecord) (bool, error) {
	if orderMonitorRecord == nil {
		r.logger.WithContext(ctx).Warn("orderMonitorRecordDao|Insert|orderMonitorRecord is nil")
		return false, nil
	}
	_, err := r.DB().Collection(model.OrderMonitorRecord{}.CollectionName()).InsertOne(ctx, *orderMonitorRecord)
	if err != nil {
		r.logger.WithContext(ctx).Error("orderMonitorRecordDao|InsertOne(", zap.Any("data", map[string]interface{}{
			"orderMonitorRecord": orderMonitorRecord,
		}), zap.Error(err))
		return false, err
	}

	return true, nil
}

